[% setvar title Add null() keyword and fundamental data type %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Add null() keyword and fundamental data type</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Nathan Wiger &lt;<a href='mailto:nate@wiger.org'>nate@wiger.org</a>&gt;
  Date: 19 Sep 2000
  Last Modified: 23 Sep 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 263
  Version: 2
  Status: Retracted
  </pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Currently, Perl has the concept of <code>undef</code>, which means that a value is
not defined. One thing it lacks, however, is the concept of <code>null</code>,
which means that a value is known to be unknown or not applicable. These
are two separate concepts.</p>
<p>The absence of a <code>null</code> concept and keyword in Perl makes it more
difficult to interface with relational databases and other medium which
utilize <code>null</code>. Modules such as <code>DBI</code> must map <code>null</code> to <code>undef</code>,
which is an imperfect match.</p>
<p>This RFC proposes a new <code>null</code> keyword and fundamental value for Perl
6.</p>
<a name='NOTES ON RETRACTION'></a><h1>NOTES ON RETRACTION</h1>
<p>This was basically universally acknowledged as the Wrong Way to
implement the idea. For more details, see the mail thread starting here:</p>
<p><a href='http://www.mail-archive.com/perl6-language@perl.org/msg04272.html' target='_blank'>www.mail-archive.com</a></p>
<p>The alternative approach of a <code>use tristate</code> pragma was determined to
be much more suitable and Perlish.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<a name='What is NULL anyways?'></a><h2>What is NULL anyways?</h2>
<p>The concept of <code>null</code> as opposed to <code>undef</code> is sometimes difficult for
people to understand. Here is Glenn Linderman's great explanation,
directly from an email he posted to the list:</p>
<p>&lt;quote&gt;
There is a difference between &quot;undefined&quot; and &quot;unknown&quot;.</p>
<p>SQL NULL, and the resultant tristate operators used in SQL, specifically
is based on NULL representing the &quot;unknown&quot; value.</p>
<p>Perl undefined is a different concept--that of an uninitialized
variable.  This is proven from its earliest versions where the value is
coerced to 0 or '' (specific values) when used (without warnings on).</p>
<p>Some Perl programs &amp; modules (including DBI) attempt to correlate NULL
and undefined, for lack of a better match of concepts (Perl is missing
the concept of NULL, SQL is missing the concept of undefined, but that
doesn't correctly imply that the concepts each language _does_ have are
correlated, or should be).</p>
<p>If you want NULL, RFC it is a new concept.  DBI could then be ported to
Perl 6, and the power of using NULL in its operators (perhaps together
with transactional variables) could make Perl an extremely powerful
database manipulation language and would make the language,
complementary to and augmenting SQL in ways no other language currently
does.</p>
<p>Any OO language with full operator overloading could write
objects/operators that behave like SQL values, and implement tristate
logic for those objects, just like SQL does.  Perhaps you should attempt
that, and RFC the failures.  I would recommend, however, that you not
attempt to use the concept of undefined to implement the concept of
NULL, at least not visibly.
&lt;/quote&gt;</p>
<a name='Why the heck do we care?'></a><h2>Why the heck do we care?</h2>
<p>As mentioned above, <code>null</code> and &lt;undef&gt; are two different things
altogether. Consider the following two examples:</p>
<pre>   undef                     null
   ------------------------  ------------------------
   $a = undef;               $a = null;
   $b = 1;                   $b = 1;
   $c = $a + b;              $c = $a + $b;

   $c is 1                   $c is null</pre>
<p>The keyword <code>null</code> means that a value is <b>known to be unknown</b>. This
means a couple important things, with semantics far different from
<code>undef</code>:</p>
<pre>   1. Any math or string operation between a null and
      non-null value results in null

   2. No null value is equal to any other null, unlike
      undef

   3. A null value is neither defined nor undefined</pre>
<p>To recap: There is no 1:1 mapping between <code>undef</code> and &lt;null&gt;. Any
attempt to do so is inaccurate. For more details, please read the
references.</p>
<a name='The new 'null' keyword'></a><h2>The new 'null' keyword</h2>
<p>The new <code>null</code> keyword can be used anywhere that <code>undef</code> can be:</p>
<pre>   my $name = null;
   null @array;
   @return = query($amount, $country, null, $time);
   die &quot;Fatal, \$name was unset!&quot; if ( $name == null );</pre>
<p>With semantics to represent the RDBMS concept of <code>null</code>. Note that the
last one works because we are simply testing against <code>null</code>. However,
the following code:</p>
<pre>   $a = null;
   $b = null;
   print '$a eq $b!' if ($a eq $b);</pre>
<p>Would not print anything, since two <code>null</code> values are not equivalent.</p>
<a name='The 'initialize' pragma'></a><h2>The 'initialize' pragma</h2>
<p>The <code>initialize</code> pragma is introduced to tell Perl what to default your
unitialized values to. By default, it will remain <code>undef</code>, same as
currently. However, this code:</p>
<pre>   use initialize 'null';   # or &quot;use initialize 'undef'&quot;

   my($a, $b);
   print &quot;Hello world!&quot; if ($a == $b);</pre>
<p>Would no longer print out <code>&quot;Hello World!&quot;</code>, since the unitialized
values $a and $b would now be set to <code>null</code>, rather than <code>undef</code>. This
allows very easy porting of RDBMS-related work. The <code>use initialize</code>
pragma should obey blocks as well:</p>
<pre>   use initialize 'null';
   my($a, $b);
   print &quot;Hello world!&quot; if ($a == $b);
   {
       use initialize 'undef';
       my($c, $d);
       print &quot;Hello universe!&quot; if ($c == $d);

   }</pre>
<p>The above example would print out &quot;Hello universe!&quot;. By obeying blocks,
you can easily embed true SQL queries in your code without disrupting
the rest of the script.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Add a <code>null</code> keyword and fundamental value that have the proper
semantics.</p>
<p>Add an <code>initialize</code> pragma that tells Perl what to initialize variables
to by default.</p>
<a name='MIGRATION'></a><h1>MIGRATION</h1>
<p>None. New functionality.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p><a href='http://www.sitelite.nl/mysql/manual_Problems.html' target='_blank'>www.sitelite.nl</a>#IDX666</p>
<p><a href='http://www.unb.ca/web/transpo/mynet/mtx19.htm' target='_blank'>www.unb.ca</a>#r2</p>
</div>
